﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WSPay.Common.Data
{
    public interface IEntity
    {
        /// <summary>
        /// 主键
        /// </summary>
        int ID { get;}
    }

    public abstract class Entity:IEntity
    {
        protected Entity()
        {
            CreateTime = DateTime.Now;
        }

        /// <summary>
        /// 主键
        /// </summary>
        public int ID { get; private set; }

        /// <summary>
        /// 是否逻辑删除
        /// </summary>
        public bool IsDelete { get; protected set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        public void Dump()
        {

            if (IsDelete) return;

            IsDelete = true;

        }

        /// <summary>
        /// 逻辑撤销删除
        /// </summary>
        public void Recovery()
        {
            IsDelete = false;
        }

        /// <summary>
        /// 是否是持久化实体
        /// </summary>
        public bool IsPersistence
        {
            get
            {
                return ID > 0;
            }
        }

    }
}
